package engine.newUi
{
	import com.greensock.TweenLite;
	import com.greensock.data.TransformAroundPointVars;
	import com.greensock.easing.Cubic;
	import com.greensock.easing.Quint;
	
	import engine.data.ModelLocator;
	import engine.data.ResPath;
	import engine.event.SceneEvent;
	import engine.event.SoundEvent;
	import engine.logic.LogSendLogic;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.tip.TipsMainLogic;
	import engine.ui.AlertUI;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.geom.Point;
	import flash.text.StyleSheet;
	import flash.utils.Timer;
	
	import newx.NxApi;
	import newx.StageInfo;
	import newx.com.config.StaticIni;
	import newx.com.control.ITabBar;
	import newx.com.control.NxClip;
	import newx.com.control.button.NxButton;
	import newx.com.control.text.NxLabel;
	import newx.com.control.window.NxWindowEvent;
	
	/**
	 * 
	 * @author gaoyq
	 * 
	 */
	public class DigCimeliaLogic
	{
		
		public static var _self:DigCimeliaLogic;
		private var _ui:DigCimeliaUI;
		
		private var allList:Array = [];
		private var item1List:Array = [];
		private var item2List:Array = [];
		/***选中的开启方式1.铜币。2.元宝***/
		private var _indexSelect:int = 0;
		/**vip等级***/
		private var vipLevel:int = 0;
		private	var		model			:ModelLocator;
		
		private var currMc:MovieClip;
		/**能不能转换1不能。0能**/
		private var luckStatus:int  = 1;
		/***记录数据**/
		private var eve:CustomMsgEvent;
		
		private var timer:Timer;
		private static var  glow:GlowFilter		= 	new GlowFilter(0x000000, .8, 4, 4, 6, BitmapFilterQuality.LOW);
		public function DigCimeliaLogic()
		{
			
		}
		
		
		public static function getInstance():DigCimeliaLogic
		{
			if(_self == null)
			{
				_self =new DigCimeliaLogic();
			}
			return _self;
		}
		
		
		public function uiinit():void
		{
			ui.lab_5.htmlStr = StaticIni.getSwfLangStrVar("UIString_1000183",[StaticIni.getIniVar("GoldCoinNeed","count")]);
			ui.lab_6.htmlStr = StaticIni.getSwfLangStrVar("UIString_1000184",[StaticIni.getIniVar("MagicCoinNeed","count")])
			ui.left_move.visible = false;
			ui.pic_list.addChild(ui.move_bg);
			ui.itemList_0.addChild(ui.left_move);
			ui.btn_get.gotoAndStop(1);
			ui.move_bg.visible = false;
			ui.lab_getGold.visible = false;
			ui.fanpaibg.visible = false;
			ui.pic_list.visible = false;
			StageInfo.stage.addChild(ui.move_pic);
			allList = StaticIni.getIniVar("getItemList","allList").split(",");
			item1List = StaticIni.getIniVar("getItemList","item1List").split(",");	
			item2List = StaticIni.getIniVar("getItemList","item2List").split(",");	
			
			var txtStyle:StyleSheet	=	new StyleSheet();
			
			txtStyle.setStyle("a:link"		,{color:"#FFFF00",textDecoration:"underline"});
			txtStyle.setStyle("a:visited"	,{color:"#"+StaticIni.getIniVar("Css_a_Task","visited")});
			txtStyle.setStyle("a:hover"	,{color:"#"+StaticIni.getIniVar("Css_a_Task","hover"),textDecoration:"none"});
			
			ui.lab_getGold.styleSheet = txtStyle;
			ui.lab_getGold.addLinkClickHandel(onLinkClick);
			
			
			ui.lab_getGold.htmlStr = StaticIni.getSwfLangStr("UIString_1000160");
			model			=	ModelLocator.getInstance();
			
//			model			.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_SEARCH_CIMILIA ),ongetCimelia);
//			
//			model			.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_CHANGE_LUCK_CIMILIA ),ongetCimelia);
			
//			model			.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_CHANGE_LUCK_CIMILIA_COMSUME ),ongetCost);
//			
//		
//			model.addEventListener( SceneEvent.SceneLoaded, onSceneLoaded );
		}
	
		private function onSceneLoaded( evt : SceneEvent ):void
		{
			model.removeEventListener( SceneEvent.SceneLoaded, onSceneLoaded );
		
			ui.pic_roomIn.source = "res\\png\\roomIn.png";
			ui.pic_roomOut.source = "res\\png\\roomOut.png";
			
//			updataUI();
		}
		
		/**
		 *获得花费转换的元宝数 
		 * @param e
		 * 
		 */
		private function ongetCost(e:CustomMsgEvent):void
		{
			TipsMainLogic.instance.showMain(StaticIni.getSwfLangStrVar("99170",[e.pList[0]]));
		}
		
		
		
		
		/**
		 *	点击超链接 
		 * 
		 */
		private function onLinkClick(val:String):void
		{
			
		}
		
		/**`
		 *获得宝物 的ID
		 * @param e
		 * 
		 */
		private function ongetCimelia(e:CustomMsgEvent):void
		{
			ui.pic_list.removeItemsEvent(MouseEvent.ROLL_OVER,picviewOverHandle);
			ui.pic_list.removeItemsEvent(MouseEvent.ROLL_OUT,picviewOutHandle);
			if(_indexSelect == 2)
			{
//				ui.move_pic.visible = false;
				eve = e;
				moveBg();
				return;
			}
			var obj:Object;
			luckStatus = model.scene.Role.GetProperties("ChangeLuckStatus");
			if(e.pList.length>1)
			{
				obj = TipsMainLogic.instance.getStaticObjWithID(e.pList[1]);
				ui.move_pic.visible = false;
				currMc["btn"].enabled = false;
			}else
			{
				obj = TipsMainLogic.instance.getStaticObjWithID(e.pList[0]);
			}
			
			ui.move_pic.name = e.pList[0];
			currMc.gotoAndPlay(1);
			currMc["pic"].source = "";
			ui.move_pic.source = "";
			currMc.addFrameScript(4,mcstop);
			function mcstop():void
			{
				var clip:NxClip = currMc["pic"];
				
				currMc.addFrameScript(4,null);
				currMc.stop();
				clip.visible = true;
				clip.source = "res\\jpg\\cimelia_"+obj.ConfigID+".jpg";
				var p:Point = clip.localToGlobal(new Point(0,0));
				ui.move_pic.x = p.x;
				ui.move_pic.y = p.y;
				ui.move_pic.source =  "res\\jpg\\cimelia_"+obj.ConfigID+".jpg";
				
				ui.move_pic.visible = true;
				if(e.pList.length>1)
				{
					ui.move_pic.visible = false;
				}else
				{
					ui.move_pic.visible = true;
				}
				ui.move_pic.scaleX = 1;
				ui.move_pic.scaleY = 1;
				var picClip:NxClip = getOneClip(obj.ConfigID) ;
				vipLevel  = model.scene.Role.GetProperties("VIPLevel");
				luckStatus = model.scene.Role.GetProperties("ChangeLuckStatus");
				if(luckStatus != 0)
				{
					ui.btn_get.visible =false;
					ui.txt_tipinfo.visible = false;
				}
				if(vipLevel >=7 && luckStatus == 0)
				{
					currMc["btn"].visible = true;
				}else
				{
					currMc["btn"].visible = false;
				}
				var overP:Point = picClip.localToGlobal(new  Point(0,0));
				if(e.pList.length>1)
				{
//					ui.left_move.x = picClip.parent.x - 15;
//					ui.left_move.y = picClip.parent.y - 15;
//					ui.left_move.visible = true;
//					ui.left_move.gotoAndPlay(1);
//					ui.left_move.addFrameScript(ui.left_move.totalFrames -1 ,stop);
//					function stop():void
//					{
//						ui.left_move.addFrameScript(ui.left_move.totalFrames -1 ,null);
//						ui.left_move.visible = false;
//						currMc["btn"].enabled = true;
//					}
//					updataCount();
					setLeftEff(picClip);
				}else
				{
					TweenLite.to(ui.move_pic, 2, {x:overP.x,y:overP.y, scaleX:.2, scaleY:.2, ease:Cubic.easeOut,onComplete:tweenLiteComplete});
					/**
					 *移动结束 
					 * 
					 */
					function tweenLiteComplete():void
					{
						ui.move_pic.visible = false;
						setLeftEff(picClip);
//						updataCount();
						model.dispatchEvent(new SoundEvent(SoundEvent.CIMELIA_GOT));
						getHaveCount();
					}
				}
			}
			
		}
		
		private function setLeftEff(p:NxClip):void
		{
			ui.left_move.x = p.parent.x - 15;
			ui.left_move.y = p.parent.y - 15;
			ui.left_move.visible = true;
			ui.left_move.gotoAndPlay(1);
			ui.left_move.addFrameScript(ui.left_move.totalFrames -1 ,stop);
			function stop():void
			{
				ui.left_move.addFrameScript(ui.left_move.totalFrames -1 ,null);
				ui.left_move.visible = false;
				currMc["btn"].enabled = true;
			}
			updataCount();
		}
		
		private function removeTimer():void
		{
			if(timer)
			{
				timer.stop();
				timer.removeEventListener(TimerEvent.TIMER,onTimerHandle);
				timer = null;
			}
		}
		
		private function moveBg():void
		{
			removeTimer();
			var radom:int = 30+ Math.random()*10;
			timer = new Timer(80);
			timer.repeatCount = radom;
			timer.addEventListener(TimerEvent.TIMER,onTimerHandle);
			timer.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerCompleteHandle);
			timer.start();
			var mc:MovieClip = ui.pic_list.getItemByIndex(0);
			ui.move_bg.x= mc.x;
			ui.move_bg.y = mc.y;
			ui.move_bg.visible = true;
		}
		private var index:int = 0;
		private function onTimerHandle(e:TimerEvent):void
		{
			if(timer.currentCount > (timer.repeatCount-5))
			{
				timer.delay = 300;
			}
				
			if(index >= 5)
			{
				index = 0;
			}
			var mc:MovieClip = ui.pic_list.getItemByIndex(index);
			ui.move_bg.x= mc.x;
			ui.move_bg.y = mc.y+15;
			index += 1;
			model.dispatchEvent(new SoundEvent(SoundEvent.TURN_CARD));
		}
		
		private function onTimerCompleteHandle(e:TimerEvent):void
		{
			currMc = ui.pic_list.getChildAt(index-1) as MovieClip;
			_indexSelect = 0;
			ongetCimelia(eve);
			model.dispatchEvent(new SoundEvent(SoundEvent.TURN_ROUND_CARD));
		}
		
		
		
		/**
		 *根据ID获得当前的物品对象引用 
		 * @param configid
		 * @return 
		 * 
		 */
		private function getOneClip(configid:int):NxClip
		{
			var i:int = 0;
			var clip:NxClip ;
			var item:MovieClip;
			var  itemList_0len:int = ui.itemList_0.row*ui.itemList_0.col;
			for( i = 0;i< itemList_0len ;i++ )
			{
				item = ui.itemList_0.getChildAt(i) as MovieClip;
				if(item["configid"] == configid)
				{
					return item["clip"];
				}
			}
			return null;
		}
		
		/**
		 *更新界面显示 
		 * 
		 */
		private function updataUI():void
		{
			var i:int = 0;
			var  itemList_0len:int = ui.itemList_0.row*ui.itemList_0.col;
			var  itemList_1len:int = ui.itemList_1.row*ui.itemList_1.col;
			var  itemList_2len:int = ui.itemList_2.row*ui.itemList_2.col;
			var  itemPicListLen:int = ui.pic_list.row*ui.pic_list.col;
			var clip:NxClip ;
			var item:MovieClip;
			var obj:Object ;
			
			for( i = 0;i< itemList_0len ;i++ )
			{
				obj =TipsMainLogic.instance.getStaticObjWithID(allList[i]);
				item = ui.itemList_0.getChildAt(i) as MovieClip;
				clip = new NxClip();
				clip.x = 5;
				clip.y = 5;
				clip.scaleContent = true;
				clip.maintainAspectRatio = false;
				clip.width = 51;
				clip.height = 51;
				clip.source = "res\\jpg\\cimelia_"+obj.ConfigID+".jpg";
				item["configid"] = allList[i];
				var lab:NxLabel = new NxLabel();
				lab.x = 5;
				lab.y = 5;
				lab.visible = false;
				item.addChild(clip);
				item.addChild(lab);
				lab.filters = [glow];
				item["labcount"] = lab;
				item["clip"] = clip;
			}
			
			for( i = 0;i< itemList_1len ;i++ )
			{
				obj =TipsMainLogic.instance.getStaticObjWithID(item1List[i]);
				item = ui.itemList_1.getChildAt(i) as MovieClip; 
				clip = new NxClip();
				clip.scaleContent = true;
				clip.maintainAspectRatio = false;
				clip.x = 5;
				clip.y = 5;
				clip.width = 32;
				clip.height = 32;
				clip.source = "res\\items\\icon_"+obj.Photo+".jpg";
				item["configid"] = item1List[i];
				item.addChild(clip);
			}
			
			for( i = 0;i< itemList_2len ;i++ )
			{
				obj =TipsMainLogic.instance.getStaticObjWithID(item2List[i]);
				item = ui.itemList_2.getChildAt(i) as MovieClip;
				clip = new NxClip();
				clip.scaleContent = true;
				clip.maintainAspectRatio = false;
				clip.x = 5;
				clip.y = 5;
				clip.width = 32;
				clip.height = 32;
				clip.source = "res\\items\\icon_"+obj.Photo+".jpg";
				item["configid"] = item2List[i];
				item.addChild(clip);
			}
			
			for(i = 0; i<itemPicListLen;i++ )
			{
				item = ui.pic_list.getChildAt(i) as MovieClip;
				clip = new NxClip();
				clip.x = 33;
				clip.y = 64;
				
				var btn:NxButton = new NxButton();
				btn.skin = "Button_2";
				btn.visible = false;
				btn.label = StaticIni.getSwfLangStr("UIString_1000632");
				btn.width = 64;
				btn.height = 28;
				btn.x = 30;
				btn.y = 135;
				btn.addEventListener(MouseEvent.CLICK,onSwitchHandle);
				btn.addEventListener(MouseEvent.MOUSE_OVER,onSwitchOverHandle)
				btn.addEventListener(MouseEvent.MOUSE_OUT,onSwitchOutHandle)
				item["btn"] = btn;
				item["pic"] = clip;
				item.face.addChild(btn);
				item.face.addChild(clip);
			}
		}
		
		private function onSwitchOverHandle(e:MouseEvent):void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLEINT_CUSTOMMSG_CHANGE_CIMILIA_COMSUME);
		}
		
		private function onSwitchOutHandle(e:MouseEvent):void
		{
			TipsMainLogic.instance.hide();
		}
		
		/**
		 * 转换宝物
		 * @param e
		 * 
		 */
		private function onSwitchHandle(e:MouseEvent):void
		{
			_indexSelect = 0;
			var btn:NxButton = e.currentTarget as NxButton;
			ui.move_pic.visible = false;
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLEINT_CUSTOMMSG_CHANGE_CIMILIA);
			model.dispatchEvent(new SoundEvent(SoundEvent.TURN_ROUND_CARD));
		}
		
		
		public function updataCount():void
		{
			ui.lab_count.text = StaticIni.getSwfLangStrVar("UIString_1000161",[model.scene.Role.GetPropertiesEx("SearchCimiliaNums")])+"/1";
			var arr:Array = model.scene.GetRecordEx("Cimilia").recArr;
			for(var i:int = 0;i<arr.length;i++)
			{
				var  itemList_0len:int = ui.itemList_0.row*ui.itemList_0.col;
				var item:MovieClip;
				var obj:Object ;
				for( var j:int = 0;j< itemList_0len ;j++ )
				{
					item = ui.itemList_0.getChildAt(j) as MovieClip;
					if(item["configid"] == arr[i][0])
					{
						if(arr[i][1]>0)
						{
							item["labcount"].visible = true;
							item["labcount"].text = arr[i][1];
						}else
						{
							item["labcount"].visible = false;
						}
					}
				}
			}
		}
		
		private function palyPic():void
		{
//			ui.pic_list.removeItemsEvent(MouseEvent.ROLL_OVER,picviewOverHandle);
//			ui.pic_list.removeItemsEvent(MouseEvent.ROLL_OUT,picviewOutHandle);
			if(model.scene.Role.GetPropertiesEx("SearchCimiliaNums") >= 1)
			{
				AlertUI.showAlert("UIString_1000084",StaticIni.getSwfLangStr("UIString_1000185"),AlertUI.OK);
				return;
			}
			if(!ui.fanpaibg.visible)
			{
				ui.fanpaibg.visible = true;
				ui.pic_list.visible = true;
				TweenLite.from(ui.fanpaibg,.5,{y:494});
				TweenLite.from(ui.pic_list,.5,{y:494,onComplete:onMoveOverHandle});
				return;
			}
			
			function onMoveOverHandle():void
			{
				setVIPoneGet();
			}
			
			ui.pic_list.removeItemsEvent(MouseEvent.CLICK,viewClickHandle);
			ui.pic_list.addItemsEvent(MouseEvent.CLICK,viewClickHandle);
			var len:int = ui.pic_list.row*ui.pic_list.col;
			var i:int = 0
			for( i = 0;i<len; i++)
			{
				var mc:MovieClip = ui.pic_list.getChildAt(i) as MovieClip;
				mc.gotoAndPlay(1);
				mc["pic"].source = "";
				mc["pic"].visible = false;
				mc["btn"].visible = false;
				mc.addFrameScript(8,mcstop);
			}
			model.dispatchEvent(new SoundEvent(SoundEvent.TURN_ROUND_CARD));
			function mcstop():void
			{
				for( i = 0;i<len; i++)
				{
					var mc:MovieClip = ui.pic_list.getChildAt(i) as MovieClip;
					mc.addFrameScript(8,null);
					mc.gotoAndStop(1);
					mc["pic"].source = "";
					mc["pic"].visible = false;
					setVIPoneGet();
				}
			}
		}
		
		
		private function setVIPoneGet():void
		{
			luckStatus = model.scene.Role.GetProperties("ChangeLuckStatus");
			vipLevel  = model.scene.Role.GetProperties("VIPLevel");
			if(vipLevel >= 8 && luckStatus == 0)
			{
				ui.btn_get.visible = true;
//				ui.txt_tipinfo.visible = true;
			}else
			{
				ui.btn_get.visible = false;
				ui.txt_tipinfo.visible = false;
			}
		}
		private function onBtn_open1ClickHandle(e:MouseEvent):void
		{
			palyPic();
			_indexSelect = 0;
			
		}
		
		
		private function onBtn_open2ClickHandle(e:MouseEvent):void
		{
			palyPic();
			_indexSelect = 1;
			
		}
		
		
		private function onClickCloseHandle(e:NxWindowEvent):void
		{
			ui.showOrHide();
		}
		
		
		private function viewOverHandle(e:MouseEvent):void
		{
			
			var item :MovieClip = e.currentTarget as MovieClip;
			var obj:Object =TipsMainLogic.instance.getStaticObjWithID(item.configid);
			//			var obj:Object = StaticIni.getIniObj(item.configid);//TipsMainLogic.instance.getStaticObjWithID(item.configid);
			if(obj == null)
				return;
			TipsMainLogic.instance.showMain(obj);
		}
		
		private function viewOutHandle(e:MouseEvent):void
		{
			TipsMainLogic.instance.hide();
		}
		
		private function picviewOverHandle(e:MouseEvent):void
		{
//			ui.pic_list.removeItemsEvent(MouseEvent.MOUSE_OVER,picviewOverHandle);
			var item :MovieClip = e.currentTarget as MovieClip;
			item.gotoAndPlay(9);
			var obj:Object =TipsMainLogic.instance.getStaticObjWithID(item.configid);
			//			var obj:Object = StaticIni.getIniObj(item.configid);//TipsMainLogic.instance.getStaticObjWithID(item.configid);
			if(obj == null)
				return;
			TipsMainLogic.instance.showMain(obj);
		}
		
		private function picviewOutHandle(e:MouseEvent):void
		{
//			ui.pic_list.addItemsEvent(MouseEvent.MOUSE_OVER,picviewOverHandle);
			var item :MovieClip = e.currentTarget as MovieClip;
			item.gotoAndStop(1);
			TipsMainLogic.instance.hide();
		}
		
		private function viewClickHandle(e:MouseEvent):void
		{
			ui.pic_list.removeItemsEvent(MouseEvent.CLICK,viewClickHandle);
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLEINT_CUSTOMMSG_GET_CIMILIA,_indexSelect);
			currMc = e.currentTarget as MovieClip;
			LogSendLogic.getInstance().btnClickNumSend(22836);
		}
		
		private function onGiftClickHandle(e:MouseEvent):void
		{
			var isCount:Boolean = getHaveCount();
			
//			moveBg();
			if(isCount)
			{
				
				SendCimeliaLogic.getInstance().ui.showOrHide();
			}else
			{
				NoticeUI.getInstance().showInfo(StaticIni.getSwfLangStr("UIString_1000209"));
			}
		}
		
		/**
		 *获取有没有可以赠达的宝物 
		 * @return 
		 * 
		 */
		private function getHaveCount():Boolean
		{
			var isCount:Boolean = false;
			var arr:Array = model.scene.GetRecordEx("Cimilia").recArr;
			for(var i:int = 0;i<arr.length;i++)
			{
				var  itemList_0len:int = ui.itemList_0.row*ui.itemList_0.col;
				var item:MovieClip;
				var obj:Object ;
				if(arr[i][1] > 0)
				{
					isCount =  true;
					ui.btn_gift.enabled = true;
					break;
				}
				isCount = false;
				ui.btn_gift.enabled = false;
			}
			return isCount;
		}
		
		private function onBtn_open1OverHandle(e:MouseEvent):void
		{
			TipsMainLogic.instance.showString(StaticIni.getSwfLangStrVar("UIString_1000183",[StaticIni.getIniVar("GoldCoinNeed","count")]));
		}
		
		private function onBtn_open2OverHandle(e:MouseEvent):void
		{
			TipsMainLogic.instance.showString(StaticIni.getSwfLangStrVar("UIString_1000184",[StaticIni.getIniVar("MagicCoinNeed","count")]));
		}
		
		/**
		 *召唤事件 
		 * @param e
		 * 
		 */
		private function onGetClickHandle(e:MouseEvent):void
		{
			
			ui.pic_list.removeItemsEvent(MouseEvent.CLICK,viewClickHandle);
			_indexSelect = 2;
			if(model.scene.Role.GetPropertiesEx("SearchCimiliaNums") >= 1)
			{
				AlertUI.showAlert("UIString_1000084",StaticIni.getSwfLangStr("UIString_1000185"),AlertUI.OK);
				return;
			}
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLEINT_CUSTOMMSG_GET_CIMILIA,_indexSelect);
			LogSendLogic.getInstance().btnClickNumSend(22837);
//			moveBg();
		}
		
		/**
		 *over 
		 * @param e
		 * 
		 */
		private function onGetOverHandle(e:MouseEvent):void
		{
			ui.btn_get.gotoAndStop(2);
			TipsMainLogic.instance.showMain(StaticIni.getSwfLangStr("EscortStr_30"));
		}
		
		/**
		 *out
		 * @param e
		 * 
		 */
		private function onGetOutHandle(e:MouseEvent):void
		{
			ui.btn_get.gotoAndStop(1);
			TipsMainLogic.instance.hide();
		}
		
		/**
		 *添加监听 
		 * 
		 */
		private function addListenter():void
		{
			ui.windowBG	.addEventListener(	NxWindowEvent.WINDOW_CLOSE,	onClickCloseHandle);
			ui.btn_open1.addEventListener(MouseEvent.CLICK,onBtn_open1ClickHandle);
			ui.btn_open1.addEventListener(MouseEvent.MOUSE_OVER,onBtn_open1OverHandle);
			ui.btn_open1.addEventListener(MouseEvent.MOUSE_OUT,viewOutHandle);
			
			ui.btn_open2.addEventListener(MouseEvent.CLICK,onBtn_open2ClickHandle);
			ui.btn_open2.addEventListener(MouseEvent.MOUSE_OVER,onBtn_open2OverHandle);
			ui.btn_open2.addEventListener(MouseEvent.MOUSE_OUT,viewOutHandle);
			
			ui.itemList_0.addItemsEvent(MouseEvent.MOUSE_OVER,viewOverHandle);
			ui.itemList_0.addItemsEvent(MouseEvent.MOUSE_OUT,viewOutHandle);
			//			ui.itemList_0.addItemsEvent(MouseEvent.CLICK,viewClickHandle);
			
			ui.itemList_1.addItemsEvent(MouseEvent.MOUSE_OVER,viewOverHandle);
			ui.itemList_1.addItemsEvent(MouseEvent.MOUSE_OUT,viewOutHandle);
			//			ui.itemList_1.addItemsEvent(MouseEvent.CLICK,viewClickHandle);
			
			ui.itemList_2.addItemsEvent(MouseEvent.MOUSE_OVER,viewOverHandle);
			ui.itemList_2.addItemsEvent(MouseEvent.MOUSE_OUT,viewOutHandle);
			//			ui.itemList_2.addItemsEvent(MouseEvent.CLICK,viewClickHandle);
			
			ui.pic_list.addItemsEvent(MouseEvent.ROLL_OVER,picviewOverHandle);
			ui.pic_list.addItemsEvent(MouseEvent.ROLL_OUT,picviewOutHandle);
			ui.pic_list.addItemsEvent(MouseEvent.CLICK,viewClickHandle);
			
			ui.btn_gift.addEventListener(MouseEvent.CLICK,onGiftClickHandle);
			
			ui.btn_get.addEventListener(MouseEvent.CLICK,onGetClickHandle);
			ui.btn_get.addEventListener(MouseEvent.MOUSE_OVER,onGetOverHandle);
			ui.btn_get.addEventListener(MouseEvent.MOUSE_OUT,onGetOutHandle);
		}
		
		
		
		/**
		 *移除监听 
		 * 
		 */
		private  function removeListenter():void
		{
			ui.windowBG	.removeEventListener(	NxWindowEvent.WINDOW_CLOSE,	onClickCloseHandle);
			ui.btn_open1.removeEventListener(MouseEvent.CLICK,onBtn_open1ClickHandle);
			ui.btn_open1.removeEventListener(MouseEvent.MOUSE_OVER,onBtn_open1OverHandle);
			ui.btn_open1.removeEventListener(MouseEvent.MOUSE_OUT,viewOutHandle);
			
			ui.btn_open2.removeEventListener(MouseEvent.CLICK,onBtn_open2ClickHandle);
			ui.btn_open2.removeEventListener(MouseEvent.MOUSE_OVER,onBtn_open2OverHandle);
			ui.btn_open2.removeEventListener(MouseEvent.MOUSE_OUT,viewOutHandle);
			
			ui.itemList_0.removeItemsEvent(MouseEvent.MOUSE_OVER,viewOverHandle);
			ui.itemList_0.removeItemsEvent(MouseEvent.MOUSE_OUT,viewOutHandle);
			//			ui.itemList_0.removeItemsEvent(MouseEvent.CLICK,viewClickHandle);
			
			ui.itemList_1.removeItemsEvent(MouseEvent.MOUSE_OVER,viewOverHandle);
			ui.itemList_1.removeItemsEvent(MouseEvent.MOUSE_OUT,viewOutHandle);
			//			ui.itemList_1.removeItemsEvent(MouseEvent.CLICK,viewClickHandle);
			
			ui.itemList_2.removeItemsEvent(MouseEvent.MOUSE_OVER,viewOverHandle);
			ui.itemList_2.removeItemsEvent(MouseEvent.MOUSE_OUT,viewOutHandle);
			//			ui.itemList_2.removeItemsEvent(MouseEvent.CLICK,viewClickHandle);
			
			
			ui.pic_list.removeItemsEvent(MouseEvent.ROLL_OVER,picviewOverHandle);
			ui.pic_list.removeItemsEvent(MouseEvent.ROLL_OUT,picviewOutHandle);
			ui.pic_list.removeItemsEvent(MouseEvent.CLICK,viewClickHandle);
			
			ui.btn_gift.removeEventListener(MouseEvent.CLICK,onGiftClickHandle);
			
			ui.btn_get.removeEventListener(MouseEvent.CLICK,onGetClickHandle);
			ui.btn_get.removeEventListener(MouseEvent.MOUSE_OVER,onGetOverHandle);
			ui.btn_get.removeEventListener(MouseEvent.MOUSE_OUT,onGetOutHandle);
		}
		
		
		public function BeforeShow():void
		{
			
			ui.bgdi.source = ResPath.SWF + "digCimelia.swf";
			vipLevel  = model.scene.Role.GetProperties("VIPLevel");
			ui.btn_get.visible =false;
			ui.txt_tipinfo.visible = false;
			ui.lab_count.text = StaticIni.getSwfLangStrVar("UIString_1000161",[model.scene.Role.GetPropertiesEx("SearchCimiliaNums")])+"/1";
			updataCount();
			addListenter();
			getHaveCount();
		}
		
		public function AfterHide():void
		{
			if(currMc)
			{
				currMc.gotoAndStop(1);
				currMc["pic"].source = "";
				currMc["pic"].visible = false;
				currMc["btn"].visible = false;
			}
			
			ui.fanpaibg.visible = false;
			ui.pic_list.visible = false;
			ui.move_pic.visible = false;
			ui.move_bg.visible = false;
			ui.left_move.visible = false;
			removeListenter();
		}
		
		public function get ui():DigCimeliaUI
		{
			if(_ui==null)
			{
				_ui	=	new DigCimeliaUI();
			}
			return _ui
		}
		
	}
}